//
//  GuideViewController.m
//  彩票项目
//
//  Created by 伍银荣 on 2021/8/11.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "GuideViewController.h"
#import "WYRTabBarController.h"

@interface GuideViewController ()
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end

@implementation GuideViewController

static NSString * const reuseIdentifier = @"Cell";

-(instancetype)init {
    _layout = [[UICollectionViewFlowLayout alloc]init];
    _layout.itemSize = kScreenSize.size;
    //滑动的方向(水平滑动)
    _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //设置间距
    _layout.minimumLineSpacing = 0;
    
    
    return [super initWithCollectionViewLayout:_layout];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //取消水平滚动条
    self.collectionView.showsHorizontalScrollIndicator = NO;
    //允许分页
    self.collectionView.pagingEnabled = YES;
    //不能弹回
    self.collectionView.bounces = NO;
    // Register cell classes(注册单元格)
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>
//返回多少组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


//一组有多少行
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    // Configure the cell
    cell.contentView.backgroundColor = [UIColor colorWithRed:(float)arc4random_uniform(256) / 255.0 green:(float)arc4random_uniform(256) / 255.0  blue:(float)arc4random_uniform(256) / 255.0  alpha:1.0];
    
    if (indexPath.row == 3) {
        UIButton *button = [[UIButton alloc]init];
        CGFloat width = 200;
        CGFloat height = 30;
        button.frame = CGRectMake((kScreenWidth - width) * 0.5, kScreenHeight - height - 30, width, height);
        [button setTitle:@"立即体验" forState:UIControlStateNormal];
        button.backgroundColor = [UIColor orangeColor];
        [cell.contentView addSubview:button];
        [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return cell;
}

- (void)buttonClicked {
    WYRTabBarController *tabBarController = [[WYRTabBarController alloc]init];
   //可以切换window的根控制器来实现效果
    UIWindow *win = [UIApplication sharedApplication].keyWindow;
    win.rootViewController = tabBarController;
    //使用modal可以实现效果,但是不应该这样做
    //[self presentViewController:tabBarController animated:NO completion:nil];
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
